[deps.host]
gcc4

[deps]
grsec

[mirrors]
http://www.kernel.org/./pub/linux/kernel/v3.x/linux-3.14.8.tar.xz
ftp://www.kernel.org/pub/linux/kernel/v3.x/linux-3.14.8.tar.xz
http://ftp.free.fr/pub/linux/kernel/v3.x/linux-3.14.8.tar.xz
http://ftp.heanet.ie/mirrors/linux/kernel/v3.x/linux-3.14.8.tar.xz

[main]
filesize=78412496
sha512=335cdb58e699da801cd31587ecda877068f13914001ed17e810571b4be713697b8f15e7d994536f664e7e032162c2d570a73364996beded0fc9319739e859866

[build]
GRSEC_VER=grsecurity-3.0-3.14.8-201406191347

# get into menuconfig using
# make HOSTCFLAGS="-D_GNU_SOURCE" HOSTLDFLAGS=-lncurses menuconfig

dopatch() {
	echo "applying patch $1"
	if ! patch -p1 < "$1" ; then
		echo "patch failed!"
		exit 1
	fi
}

#noperl and qemu patches from landley.net/aboriginal
dopatch "$K"/linux-noperl-timeconst.patch

# fix the broken "ncurses detector" which fails, and even worse removes our HOSTLDFLAGS
dopatch "$K"/linux-menuconfig.patch

# work around mismatch between devicename and channel name in 9p virtfs code
# p9_virtio_create gets something like "/dev/chan" and the channel name is "chan"
dopatch "$K"/linux-virtio9p.patch

# patches to support busybox trap and sed with strict musl BRE engine
dopatch "$K"/linux-3.8-trap.patch
dopatch "$K"/linux-3.8-posix_sed.patch

if [ -z "$DISABLE_GRSEC" ] ; then
	patchname="$GRSEC_VER".patch
	tar xf "$C"/"$patchname".tar.xz || exit 1
	ln -sf "$patchname" grsec.patch
	dopatch grsec.patch
fi

export ARCH=$A
linux_config="$K"/linux.config

if [ -z "$HOSTCC" ] ; then
	HOSTCC="$CC"
fi

if [ "$A" = arm ] ; then
	[ -z "$ARM_ARCH" ] && (echo "error: need to set ARM_ARCH to 4-7" ; exit 1)
	linux_config="$linux_config $K/linux.config.armv${ARM_ARCH}l"
fi

cat "$linux_config" > my.config

make V=1 ARCH=$A allnoconfig HOSTCFLAGS="-D_GNU_SOURCE" \
  KCONFIG_ALLCONFIG=my.config DISABLE_PAX_PLUGINS=y || exit 1

# usually when using an ARM/MIPS system you dont want to build a generic kernel
# you have to use a heavily patched vendor specific one
if [ "$A" = "arm" ] || [ "$A" = "mips" ] ; then
	SKIP_KERNEL_COMPILE=1
fi

if [ -z "$SKIP_KERNEL_COMPILE" ] ; then

#let make create dependencies, otherwise parallel build wont work
make v=1 CC="$CC" HOSTCC="$HOSTCC" ARCH=$A HOSTCFLAGS=-D_GNU_SOURCE \
  DISABLE_PAX_PLUGINS=y dep || exit 1

make V=1 -j$MAKE_THREADS CC="$CC" ARCH=$A HOSTCC="$HOSTCC" \
  HOSTCFLAGS=-D_GNU_SOURCE DISABLE_PAX_PLUGINS=y || exit 1

make INSTALL_MOD_PATH=$R DISABLE_PAX_PLUGINS=y modules_install || exit 1

mkdir -p $R/boot $R/lib/modules $R/lib/firmware
cp System.map $R/boot/

if [ "$A" = arm ] ; then
	kpath="arch/arm/boot/zImage"
else
	kpath="arch/x86/boot/bzImage"
fi
cp $kpath $R/boot/vmlinuz

fi

# "build" headers into dest/
# we need to build them after the kernel because grsec assumes this order
# otherwise some generated headers won't be found
make V=1 ARCH=$A HOSTCFLAGS=-D_GNU_SOURCE INSTALL_HDR_PATH=dest \
  DISABLE_PAX_PLUGINS=y headers_install || exit 1

# remove junk from kernel headers
find dest/include \( -name .install -o -name ..install.cmd \) -delete


exit 0
